<!-- 问题反馈 列表 -->
<template>

	<uni-list v-if="listData.length" class="query-list" :avatar-circle="true">
		<uni-list-item v-for="(item,index)  in listData" :title="item.sqlx.substring(2)" direction="column" clickable showArrow
			:key="index"  @click="detailsClick(item)">
			<template v-slot:footer>
				<view class="query-describe">
					<text>提交时间：</text>
					<text>{{item.sqsj}}</text>
				</view>
				<view class="query-describe">
					<text>处理进度：</text>
					<text>{{zfdmFormatter(item.gzdzt)}}</text>
				</view>
				<view class="query-describe ">
					<text>提交内容：</text>
					<text>{{item.bxnr}}</text>
				</view>
			</template>
		</uni-list-item>
	</uni-list>

	<cUserinfoSelect v-if="!formdata.yhbh" @setYhbh="doSelectYhbh" />
</template>

<script setup lang="ts">
	import cUserinfoSelect from "@/pages/bspsd/components/userinfo-select.vue";
	import { GetYhJbxx } from "@/api/request/GetYhJbxx";
	import { getJgbm } from "@/utils/storage";
	import { GzdGzslSelectiveGet } from "@/api/request/GzdGzslSelectiveGet";
	import { SysZfdmQuery } from "@/api/request/SysZfdmQuery";
	import { getSysZfdm } from "@/api/syszfdm"
	import { SysZfdm } from "@/api/tables/SysZfdm"
	import { GzdGzsl } from "@/api/tables/GzdGzsl"
	import { ref, onBeforeMount } from 'vue';

	let formdata = ref({ yhbh: '', })
	let listData = ref<Array<GzdGzsl>>([])
	
	const SQZTLIST = ref<Array<SysZfdm>>([])

	onBeforeMount(() => {
		getListSQZT()
	})

	const getListSQZT = () => {
		SysZfdmQuery({
			data:{zfdm:{dmzl:"SQZT"}},
			success: (result) => {
				let list = result || []
				SQZTLIST.value = list
			}
		})
		// getSysZfdm({
		// 	dmzl: "SQZT",
		// 	success: (result) => {
		// 		SQZTLIST.value = result || []
		// 	}
		// })
	}
	function getListData() {
		GzdGzslSelectiveGet({
			data: {
				jgbm: getJgbm(),
				bxslrid: "9999",
				isNil: '0',
				yhbh: formdata.value.yhbh,
			},
			success: (res) => {
				listData.value = res
			},
			fail: (code, message) => {
				console.log(code, message)
			}
		})
	}

	function doSelectYhbh(yhbh : string) {
		GetYhJbxx({
			data: { yhbh: yhbh },
			success: (res) => {
				if (res.length != 1) {
					uni.showModal({
						title: '错误提示',
						content: '查询数据时发生内部逻辑错误',
						showCancel: false,
						success: function () {
							uni.navigateBack()
						}
					})
					return
				}

				formdata.value = Object.assign({}, formdata.value, res[0])
				getListData()
			},
			fail: (_code, message) => {
				uni.showModal({ content: message, showCancel: false })
				uni.navigateBack()
			}
		})
	}
	function detailsClick(item){
		uni.navigateTo({ url: './details?detailsData=' + JSON.stringify(item)  })
	}
	function zfdmFormatter(value) {
		let zfdmArr = SQZTLIST.value.filter(item => item.dmbh == value);
		if (zfdmArr.length) {
			return zfdmArr[0].dmnr
		}
		return '';
	}
</script>

<style lang="scss" scoped>
	.query-list {

		.query-describe {
			padding-top: 10rpx;
			line-height: 1.5;
			color: #999;
			font-size: 24rpx;

		}
	}
</style>